package com.galo.service.controller;

import com.alibaba.fastjson.JSONObject;
import com.galo.service.common.Result;
import com.galo.service.common.ResultGenerator;
import com.galo.service.service.SmartPlugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 智能插座
 * @Auther: lxlin
 * @Date: 2018/11/15 16:43
 * @Description:
 */
@RestController
@RequestMapping("/api/v1/plug")
public class SmartPlugController {

    @Autowired
    private SmartPlugService plugService;

    /**
     * 开启/关闭智能插座接口
     * @return
     */
    @PostMapping("/control")
    private Result control(@RequestBody String body){

        JSONObject object = JSONObject.parseObject(body);
        String devsn = object.getString("devsn");
        String sta = object.getString("sta");
        plugService.control(devsn,sta);
        return ResultGenerator.genSuccessResult("指令发送成功！");
    }
}
